package com.yidu.BusinessData.service.impl;

import com.yidu.BusinessData.entity.Broker;
import com.yidu.BusinessData.entity.TradingSeats;
import com.yidu.BusinessData.mapper.TradingSeatsMapper;
import com.yidu.BusinessData.service.TradingSeatsServce;
import com.yidu.CashAdministration.entity.MoneyAllocateEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 席位实现类
 * @author zhouhongyu
 * @since 2022/8/16
 * @version 1.0
 */
@Service
public class TradingSeatsImpl implements TradingSeatsServce {
    @Autowired
    private TradingSeatsMapper tradingSeatsMapper;//自动装配

    @Override
    public int selectCount() {
        return tradingSeatsMapper.selectCount();
    }

    /**
     * 重写条件查询席位方法
     * @param seatName
     * @param seatType
     * @param page
     * @param limit
     * @return
     */
    @Override
    public List<TradingSeats> selectTradingSeats(String seatName,String seatType, int page, int limit) {
        Map map = new HashMap();
        map.put("strWrteem",Splicing(seatName,seatType));
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        return tradingSeatsMapper.selectTradingSeats(map);
    }

    /**
     * 重写增加席位数据的方法
     * @param seats
     * @return
     */
    @Override
    public int insertTradingSeats(TradingSeats seats) {
        return tradingSeatsMapper.insertTradingSeats(seats);
    }

    /**
     * 重写删除席位数据的方法
     * @param seatId
     * @return
     */
    @Override
    public int deleteTradingSeats(String seatId) {
        return tradingSeatsMapper.deleteTradingSeats(seatId);
    }

    /**
     * 重写修改席位数据的方法
     * @param tradingSeats
     * @return
     */
    @Override
    public int updateTradingSeats(TradingSeats tradingSeats) {
        return tradingSeatsMapper.updateTradingSeats(tradingSeats);
    }

    /**
     * 下拉表格
     * @return
     */
    @Override
    public List<Broker> selectBroker1() {
        return tradingSeatsMapper.selectBroker1();
    }


    public String Splicing(String seatName,String seatType) {
        StringBuffer sqlWhere = new StringBuffer("") ;
        if (seatName !=null && !seatName.equals("")){
            sqlWhere.append(" and seatName like '%"+seatName+"%'");
        }if(seatType.equals("1")){
                sqlWhere.append(" and seatType = "+seatType);
        }if(seatType.equals("2")){
                sqlWhere.append(" and seatType = "+seatType);
        }

        System.out.println(sqlWhere+"builber");
        return sqlWhere.toString();
    }

}
